/*
 * @Date: 2023-12-26 13:59:25
 * @LastEditors: lyx
 * @LastEditTime: 2023-12-26 15:18:25
 * @FilePath: \taro-template3\src\sub_common\pages\auth\index.tsx
 * @Description: 登录入口文件，在这里根据终端环境（微信小程序/微信公众号/h5）分别进入各自的登入入口
 */
import { Loading } from "@nutui/nutui-react-taro";
import { View } from "@tarojs/components";
import { useEffect } from "react";
import { redirectTo } from "@tarojs/taro";
import { getSearchParams } from "@/lib/get-search-params";
import styles from "./index.module.scss";
function Auth() {
  /**
   * 跳转登录逻辑
   * @param {}
   * @return
   */
  const formatBackUrl = (url: string) => {
    return (
      url +
      `?backurl=${getSearchParams("backurl")}&isSwitchTab=${getSearchParams(
        "isSwitchTab"
      )}`
    );
  };
  const goLogin = () => {
    if (process.env.TARO_ENV === "weapp") {
      redirectTo({
        url: formatBackUrl("/sub_common/pages/auth/wechat-mini-program/index"),
      });
    }
    // if (process.env.TARO_ENV === "h5") {
    //   if (isWeChat()) {
    //     redirectTo({
    //       url: formatBackUrl("/sub_common/pages/auth/wechat/index"),
    //     });
    //   } else {
    //     redirectTo({
    //       url: formatBackUrl("/sub_common/pages/auth/login/index"),
    //     });
    //   }
    // }
  };

  useEffect(() => {
    setTimeout(() => {
      goLogin();
    }, 30);
  }, []);

  return (
    <View className={styles["auth-login-wrapper"]}>
      <Loading />
    </View>
  );
}

export default Auth;
